package com.sihuatech.coreagent.core.communication.entity;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.sihuatech.coreagent.until.Consts;



@JsonInclude(value = Include.NON_NULL)
public class Response implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private Object data;

    public Response() {
        super();
    }

    public Response(Integer code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    public Response(Integer code, String message, Object data) {
        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    public void setCodeAndMessage(Integer code,String message) {
    	this.code = code;
    	this.message = message;
    }
    
    public void setCodeAndMessageAndData(Integer code,String message,Object data) {
    	this.code = code;
    	this.message = message;
    	this.data = data;
    }

    public void success() {
        this.code = Consts.SUCCESS;
        this.message = Consts.SUCCESS_MSG;
    }

    public void fail() {
        this.code = Consts.FAIL;
        this.message = Consts.FAIL_MSG;
    }

    public void failWithMessage(String msg) {
        this.code = Consts.FAIL;
        this.message = msg;
    }

    public static Response ofFail(Object data, String msg){
        return new Response(Consts.FAIL, msg, data);
    }

    public static Response ofFail(Object data){
        return new Response(Consts.FAIL, Consts.FAIL_MSG, data);
    }

    public static Response ofFail(String message){
        return new Response(Consts.FAIL, message, null);
    }

    public static Response ofSuccess(Object data, String msg){
        return new Response(Consts.SUCCESS, msg, data);
    }

    public static Response ofSuccess(Object data){
        return new Response(Consts.SUCCESS, Consts.SUCCESS_MSG, data);
    }

    public static Response ofSuccess(String message){
        return new Response(Consts.SUCCESS, message, null);
    }
}
